from sympy import symbols, pi, exp, log
from sympy.stats import Probability, Normal

X = [1, 2, 3, 4, 5, 3, 4, 2, 5, 6]
x = symbols('x')

m, s = symbols('m s')
#  pdf
pdf = 1/ (s*(2*pi)**0.5)*exp(-(x-m)**2/(2*s**2))
logpdf = log(pdf)
print(logpdf)

logP = 0
for xi in X:
    logP += logpdf.subs({x:xi})

print(logP)

from sympy import diff

logp_diff_m = diff(logP, m)
logp_diff_s = diff(logP, s)

print('m偏导数:',str(logp_diff_m))
print('s偏导数:',str(logp_diff_s))

from sympy import simplify

logp_diff_m = simplify(logp_diff_m)
print(logp_diff_m)

logp_diff_s = simplify(logp_diff_s)
print(logp_diff_s)

from sympy import solve

funcs = [logp_diff_s, logp_diff_m]
solve(funcs,[m, s])